app
.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
	var gridId = $scope.gridId;
	
	$scope.bindBtn = function(event) {
		if(gridId == 3) { // 按钮监听-【物料出库明细】
			$scope.listenGrid3(event);
		}else if(gridId == 7) { // 按钮监听-【物料借用单】
			$scope.listenGrid7(event);
		}else if(gridId == 8) { // 按钮监听-【物料转移单明细】
			$scope.listenGrid8(event);
		}else if(gridId == 9) { // 按钮监听-【员工月度绩效申报】
			$scope.listenGrid9(event);
		}else if(gridId == 10) { // 按钮监听-【物料入库明细】
			$scope.listenGrid10(event);
		}else if(gridId == 12) { // 按钮监听-【社保付款单】
			$scope.listenGrid12(event);
		}else if(gridId == 13) { // 按钮监听-【公积金付款单】
			$scope.listenGrid13(event);
		}else if(gridId == 14) { // 按钮监听-【个税付款单】
			$scope.listenGrid14(event);
		}else if(gridId == 15) { // 按钮监听-【预支台账明细】
			$scope.listenGrid15(event);
		}else if(gridId == 17) { // 按钮监听-【预支账户报销单列表】
			$scope.listenGrid17(event);
		}else if(gridId == 18) { // 按钮监听-【应付账户台账明细】
			$scope.listenGrid18(event);
		}else if(gridId == 19) { // 按钮监听-【应付账户支付】
			$scope.listenGrid19(event);
		}else if(gridId == 20) { // 按钮监听-【预约调拨详情】
			$scope.listenGrid20(event);
		}else if(gridId == 21) { // 按钮监听-【资金登记单】
			$scope.listenGrid21(event);
		}else if(gridId == 22) { // 按钮监听-【透明计划申报】
			$scope.listenGrid22(event);
		}else if(gridId == 23) { // 按钮监听-【预付款认领单】
			$scope.listenGrid23(event);
		}else if(gridId == 24) { // 按钮监听-【亚马逊店铺管理】
			$scope.listenGrid24(event);
		}else if(gridId == 25) { // 按钮监听-【资金认领单】
			$scope.listenGrid25(event);
		}else if(gridId == 26) { // 按钮监听-【万里汇货币兑换子表】
			$scope.listenGrid26(event);
		}else if(gridId == 27) { // 按钮监听-【VAT申报】
			$scope.listenGrid27(event);
		}else if(gridId == 28) { // 按钮监听-【万里汇提款单子表】
			$scope.listenGrid28(event);
		}else if(gridId == 29) { // 按钮监听-【预付款退回申请单子表】
			$scope.listenGrid29(event);
		}else if(gridId == 30) { // 按钮监听-【万里汇CNY付款单】
			$scope.listenGrid30(event);
		}else if(gridId == 31) { // 按钮监听-【万里汇预付款退回子表】
				$scope.listenGrid31(event);
		}else if(gridId == 32) { // 按钮监听-【VAT申报详情】
			$scope.listenGrid32(event);
		}else if(gridId == 33) { // 按钮监听-【万里汇补账单】
			$scope.listenGrid33(event);
		}else if(gridId == 34) { // 按钮监听-【万里汇预付款入账单】
			$scope.listenGrid34(event);
		}else if(gridId == 35) { // 按钮监听-【万里汇外币付款单】
			$scope.listenGrid35(event);
		}else if(gridId == 36) { // 按钮监听-【万里汇预付款对账单】
			$scope.listenGrid36(event);
		}else if(gridId == 37) { // 按钮监听-【财务工资小计部门维护】
			$scope.listenGrid37(event);
		}else if(gridId == 38) { // 按钮监听-【预约调拨取消单】
			$scope.listenGrid38(event);
		}else if(gridId == 39) { // 按钮监听-【手工分配单】
			$scope.listenGrid39(event);
		}else if(gridId == 40) { // 按钮监听-【员工档案表】
			$scope.listenGrid40(event);
		}else if(gridId == 41) { // 按钮监听-【职能费用申请】
			$scope.listenGrid41(event);
		}else if(gridId == 42) { // 按钮监听-【付款申请单】
			$scope.listenGrid42(event);
		}else if(gridId == 43) { // 按钮监听-【财务交易类型子表】
			$scope.listenGrid43(event);
		}else if(gridId == 44) { // 按钮监听-【费用结算返还单】
			$scope.listenGrid44(event);
		}
	}
	
	$scope.listenGrid3= function(event) {
    	var t = this;
		switch(event){
			case 'event-to-select-stock': // 选取物料库存
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TWL_Stock', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
    },

	$scope.listenGrid7= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TWL_Stock_For_Borrow', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
    $scope.listenGrid8= function(event) {
    	var t = this;
		switch(event){
			case 'event-to-select-stock': // 选取物料库存
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TWL_Stock', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
    },
	$scope.listenGrid9= function(event) {//员工月度绩效申报
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TB_UserMonthPerformance', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
    $scope.listenGrid10= function(event) {
    	var t = this;
		switch(event){
			case 'event-to-select': // 选取物料
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TB_Material', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
    },

	$scope.listenGrid12= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增社保付款单
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.userMonthPerformanceId);
                }
                $scope.showModalCheckBox('TB_UserMonthPerformanceSb', 'userMonthPerformanceId', listUkey);
                break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();

				//计算逻辑
				var societyCompany = 0;
				var societyPersonal = 0;
				var orgName = "";
				for (let n = 0; n < $scope.subGrid.sonlist.length; n++) {
					orgName = $scope.subGrid.sonlist[n].orgName
					societyCompany = societyCompany + Number($scope.subGrid.sonlist[n].retirementCompany)+ Number($scope.subGrid.sonlist[n].loseWorkCompany)+ Number($scope.subGrid.sonlist[n].injuryCompany)
					societyPersonal = societyPersonal + Number($scope.subGrid.sonlist[n].retirementPersonal)+ Number($scope.subGrid.sonlist[n].loseWorkPersonal)
				}
				$scope.valueMap['orgName'] = orgName;
				$scope.valueMap['healthCompany'] = healthCompany;
				$scope.valueMap['healthPersonal'] = healthPersonal;
				$scope.valueMap['societyTol'] = societyCompany+societyPersonal;
				break;
			}
		};
	},
	$scope.listenGrid13= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增公积金付款单
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.userMonthPerformanceId);
                }
                $scope.showModalCheckBox('TB_UserMonthPerformanceGjj', 'userMonthPerformanceId', listUkey);
                break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();

				//计算逻辑
				var accumulationFundCompany = 0;
				var accumulationFundPersonal = 0;
				var orgName = "";
				for (let n = 0; n < t.c.subGridObj.c.sonlist.length; n++) {
					orgName = t.c.subGridObj.c.sonlist[n].orgName
					accumulationFundCompany = accumulationFundCompany + Number(t.c.subGridObj.c.sonlist[n].accumulationFundCompany)
					accumulationFundPersonal = accumulationFundPersonal + Number(t.c.subGridObj.c.sonlist[n].accumulationFundPersonal)
				}
				$scope.valueMap['orgName'] = orgName;
				$scope.valueMap['accumulationFundCompany'] = accumulationFundCompany;
				$scope.valueMap['accumulationFundPersonal'] = accumulationFundPersonal;
				$scope.valueMap['accumulationTol'] = accumulationFundCompany+accumulationFundPersonal;
				break;
			}
		};
	},
	$scope.listenGrid14= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增个税付款单
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TB_UserPayApplyGs', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},

	$scope.listenGrid15= function(event) {//预支台账明细
		var t = this;
		switch(event){
			case 'event-to-add': // 新增预支台账明细
			{
				var id = $scope.valueMap['id'];
				var code = $scope.valueMap['code'];
				var name = $scope.valueMap['name'];
				if(code==undefined || code==null || code==''){
					layer.msg("请先选择预支账户编码!");
					return;
				}
				$scope.subGrid.sonlist.push({
					id: null,
					pid:id,
					pCode: code,
					pName: name,
					createTime: '',
					companyName:'',
					companyInfoId : '',
					advanceTypeCode : '',
					advanceTypeName : '',
					vjylx : '',
					detailName : '',
					unitPrice : 0,
					quantity : 0,
					totalPrice : 0,
					remark : '',
					annexFile : '0个附件',
				});
				break;
			}
			case 'event-to-del'://删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					for (var i = 0; i < datas.length; i++) {
						var index = datas[i]['_ys_sub_grid_index'];
						if(datas[index].id!=undefined && datas[index].id!=null && datas[index].id!=''){
							_list[i] = datas[i].id;
						}

					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwAdvanceAccountDetail/toDel',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;


			}
		};
	},

	$scope.listenGrid17= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				var code = $scope.valueMap['code'];
				var advanceAccountId = $scope.valueMap['advanceAccountId'];//预支账户管理表id
				if(code==undefined || code==null || code==''){
					layer.msg("请先选择预支账户编码!");
					return;
				}
				var companyVid = $scope.valueMap['companyVid'];//所属公司编码
				if(companyVid==undefined || companyVid==null || companyVid==''){
					layer.msg("请先选择所属公司!");
					return;
				}
				
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.id);
                }
                $scope.showModalCheckBox('TCW_AdvanceAccountDetail', 'id', listUkey);
                // TODO
				//layui.YsModal.init({modalKey: 'TCW_AdvanceAccountDetail', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, extraData:{}, conditionsDefault: [{code: 'pid', value: advanceAccountId},{code: 'companyInfoVid', value: companyVid}]});
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();

				//计算本次报销金额
				var totalPriceByThis = 0;
				if(t.c.subGridObj.c.sonlist!=null && t.c.subGridObj.c.sonlist.length>0){
					for(var i=0;i<t.c.subGridObj.c.sonlist.length;i++){
						var totalPriceByItem = parseFloat(t.c.subGridObj.c.sonlist[i].totalPrice);
						if(totalPriceByItem){
							totalPriceByThis = totalPriceByThis+totalPriceByItem;
						}
					}
				}
				$scope.valueMap['totalPriceByThis'] = totalPriceByThis;
				break;
			}
		};
	},

	$scope.listenGrid18= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增应付台账明细
			{
				$scope.subGrid.sonlist.push({});
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},

	$scope.listenGrid19= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				var needPayAccountCode = $scope.valueMap['needPayAccountCode'];//应付账户编码
				if(needPayAccountCode==undefined || needPayAccountCode==null || needPayAccountCode==''){
					layer.msg("请先选择应付账户!");
					return;
				}
				
				//layui.YsModal.init({modalKey: 'TCW_NeedPayLedgerDetail', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, extraData:{}, conditionsDefault: [{code: 'needPayAccountCode', value: needPayAccountCode}]});
				

            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.id);
                }
                $scope.showModalCheckBox('TCW_NeedPayLedgerDetail', 'id', listUkey);
				// TODO
				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},

	$scope.listenGrid20 = function(event) {
		switch(event){
			case 'event-to-select': // 选取Listing普品
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.productCode);
                }
                $scope.showModalCheckBox('TP_ProductActive', 'code', listUkey);
            	break;
			}
			case 'event-to-delete-batch': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid21= function(event) {//资金登记单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vid);
                }
                $scope.showModalCheckBox('THR_OperateCompanyBankInfo', 'vid', listUkey);
                break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwCapitalRegister/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.closeAll();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.closeAll();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},
	$scope.listenGrid22= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					annexFile : '0个附件',
				});
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid23= function(event) {//预付款认领单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vid);
                }
                $scope.showModalCheckBox('THR_OperateCompanyBankInfo', 'vid', listUkey);
                break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwCapitalBusinessCost/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.closeAll();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.closeAll();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},

	$scope.listenGrid24= function(event) {//新增亚马逊店铺
		var t = this;
		switch(event){
			case 'event-to-select': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.id);
                }
                $scope.showModalCheckBox('TB_Site', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},

	$scope.listenGrid25= function(event) {//资金认领单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vid);
                }
                $scope.showModalCheckBox('THR_OperateCompanyBankInfo', 'vid', listUkey);
                break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwCapitalClaim/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.closeAll();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.closeAll();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},
	$scope.listenGrid26= function(event) {//万里汇货币兑换子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					hcAmount : '0',
					hrAmount : '0',
					exchangeRate : '0',
					hcCurrency : 'CNH',
					hrCurrency : 'CNH',
				});
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid27= function(event) {// VAT申报明细
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vatNo);
                }
                $scope.showModalCheckBox('THR_OperateCompanyEuropeTrade', 'vatNo', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid28= function(event) {//万里汇提款单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vid);
                }
                $scope.showModalCheckBox('TB_CompanyBankInfo', 'vid', listUkey);
                break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwWanliDrawing/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},
	$scope.listenGrid29= function(event) {//预付款退回申请子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					vJyLx : '运营服务→预付款退回',
					accountType : 1,
				});
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid30= function(event) {// 万里汇CNY付款单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.vid);
                }
                $scope.showModalCheckBox('TCW_PartnerBankInfo', 'vid', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid31= function(event) {//万里汇预付款退回子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.paymentReturnItemId);
                }
                $scope.showModalCheckBox('TCW_PaymentReturnWl', 'paymentReturnItemId', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					layer.confirm('确定要删除吗？', {icon: 3}, function () {
						var flax = false;
						for (var i = 0; i < datas.length; i++) {
							if(datas[i].statePay === 1 || datas[i].statePay === 2){
								flax = true;
								return layer.msg('选中数据不允许删除,请核实后再操作!')
							}
						}
						$scope.subGrid.deleteBatch();
						layer.closeAll();
					})
				}
				break;
			}
			case 'event-to-tzWanli': // 跳转万里汇
			{
				window.open('https://portal.worldfirst.com.cn/login?loginType=EMAIL&region=CN', '_blank');
				break;
			}
			case 'event-to-zrWanli': // 转入万里汇
			{
				var t = this;
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var checkedDatas = checkStatus.data;
				if (checkedDatas.length == 0){
					return layer.msg("至少选择一条数据,请核实后在操作！");
				}else if (checkedDatas.length > 1){
					return layer.msg("只允许选择一条数据,请核实后在操作！");
				}
				for (var i = checkedDatas.length - 1; i >= 0; i--) {
					var id = checkedDatas[i]['id'];
				}
				var index= layer.msg('转入万里汇中,请勿重复操作!', { icon: 16, shade: 0.01 , time: false});
				$.ajax({
					async: true,
					type: "GET",
					url: '/api/inter/tcwWanliPaymentReturn/zrWanli',
					data: {id: id},
					success: function (data) {
						if (data.code == 0) {
							layer.close(index);
							layer.msg(data.msg);
							location.reload();
						} else {
							layer.close(index);
							alert(data.msg);
							location.reload();
						}
					}
				});
				break;
			}
		};
	},
	$scope.listenGrid32= function(event) {// VAT申请
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.cbbId);
                }
                $scope.showModalCheckBox('TS_FilesInfo', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid33= function(event) {
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TCW_DepositPlatform', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
    $scope.listenGrid34= function(event) {//万里汇预付款入账单
        var t = this;
        switch(event){
            case 'event-to-add': // 新增
            {
                var domForm = $('#' + window.formObj.c.id_form);
                var reconciliationBid = domForm.find('input[name="reconciliationBid"]').val();
                if(reconciliationBid==undefined || reconciliationBid==null || reconciliationBid==''){
                    return layer.msg("请先选择对账单号！");
                }
                
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.id);
                }
                $scope.showModalCheckBox('TCW_WanliReconciliationItem_ByRecorded', 'id', listUkey);
                //layui.YsModal.init({modalKey: 'TCW_WanliReconciliationItem_ByRecorded', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, extraData:{}, conditionsDefault: [{code: 'pbid', value: reconciliationBid}]});
                break;
            }
            case 'event-to-del': // 删除
            {
                var t1 = t.c.subGridObj;
                var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
                var datas = checkStatus.data;
                if (datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var _list = [];
                    //console.log('datas',datas);
                    for (var i = 0; i < datas.length; i++) {
                        if(datas[i].itemId!=undefined && datas[i].itemId!=null && datas[i].itemId!=''){
                            _list.push(datas[i].itemId);
                        }
                    }
                    layer.confirm('确定要删除吗？', { icon: 3 }, function() {
                        //console.log('_list',_list);
                        if(_list!=null && _list.length>0){
                            layer.msg('处理中', { icon: 16, shade: 0.01 });
                            $.ajax({
                                url: '/api/inter/tcwWanliPrepaymentRecorded/toDelByItem',
                                data: "list=" + _list,
                                type: 'POST',
                                async: true,
                                success: function(res) {
                                    layer.closeAll();
                                    layer.msg(res.msg);
                                    for (var i = datas.length - 1; i >= 0; i--) {
                                        var indexNum = datas[i]['_ys_sub_grid_index'];
                                        $scope.subGrid.sonlist.splice(indexNum, 1);
                                    }
                                }, error: function() {
                                    layer.closeAll();
                                    layer.msg("删除失败，请稍后再试！", { icon: 2 });
                                }
                            });
                        }else {
                            for (var i = datas.length - 1; i >= 0; i--) {
                                var index = datas[i]['_ys_sub_grid_index'];
                                $scope.subGrid.sonlist.splice(index, 1);
                            }
                        }

                    }, function() {
                    });
                }
                break;
            }
        };
    },
	$scope.listenGrid35= function(event) {// 万里汇外币付款单
		switch(event){
			case 'event-to-add': // 新增
			{
				var payType = $scope.valueMap['payType'];
				if(payType == 1) {
					var selectedDatas = [];
					//回填数据的代码
					var gridDatas = $scope.subGridObj.sonlist;
					for (var i = 0; i < gridDatas.length; i++) {
						var row = {};
						row = gridDatas[i];
						row.id = row.relativeId;
						selectedDatas.push(row);
					}
					layui.YsModal.init({modalKey: 'THR_TransparencyProgram', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, sameCode: ''});
				} else if(payType == 2) {
					var selectedDatas = [];
					//回填数据的代码
					var gridDatas = t.c.subGridObj.getData();
					for (var i = 0; i < gridDatas.length; i++) {
						var row = {};
						row = gridDatas[i];
						row.id = row.relativeId;
						selectedDatas.push(row);
					}
					layui.YsModal.init({modalKey: 'THR_VatApplyDetail', type: 'checkbox', uniqueKey: 'id', parentObj: t.c.subGridObj, selectedData: selectedDatas, sameCode: ''});
				} else if(payType == 3) {
					t.c.subGridObj.c.sonlist.push({
						fee: 0
					});
					t.c.subGridObj.reloadGrid();
					break;
				} else {
					layer.msg('支付类型有误');
				}
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid36= function(event) {// 万里汇预付款对账单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.wanliPrepaymentPoolingId);
                }
                $scope.showModalCheckBox('TCW_WanliPrepaymentPooling', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},

	$scope.listenGrid37= function(event) {//财务工资小计部门维护
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.orgid);
                }
                $scope.showModalCheckBox('TS_OrganizationInfo_ByFinanceSalary', 'orgid', listUkey);
                break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwFinanceSalaryClassify/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},
	$scope.listenGrid38= function(event) {// 预约调拨取消单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.allocateDetailId);
                }
                $scope.showModalCheckBox('TCC_AllocateDetail-Un_Distribute', 'id', listUkey);
                break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},
	$scope.listenGrid39= function(event) {// 手工分配单
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                for(var i=0;i<$scope.subGrid.sonlist.length;i++){
                	var data = $scope.subGrid.sonlist[i];
                	listUkey.push(data.id);
                }
                $scope.showModalCheckBox('TCC_AllocateDetail-Un_Distribute', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	},


	$scope.listenGrid40= function(event) {//员工档案表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					userId : window.formObj.getValueByName('userId'),
					recordTime : "",
					recordType : '0',
					remark : "",
				});
				break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/thrUserArchives/toDelRecord',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},


	$scope.listenGrid41= function(event) {//职能费用申请子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					vgsbm : "",
					vgsjc : "",
					tradeTypeId : "",
					vremark : "",
					recoverableAmount : '0',
					userBankInfoId : "",
					_ys_uerBankInfoUserName : "",
					vyhzhmc : "",
					vkhh : "",
					vyhzh : "",
					remark : "",
					annexFile : "0个附件",
				});
				break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwRoleCostApply/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},

	$scope.listenGrid42= function(event) {//付款申请单子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					vgsbm : "",
					vgsjc : "",
					tradeTypeId : "",
					vremark : "",
					paymentAmount : "0",
					partnerBankInfoId : "",
					vid : "",
					partnerName : "",
					vkhh : "",
					vyhzh : "",
					remark : "",
					annexFile : "0个附件",
					receiptAnnexFile : "0个附件",
				});
				break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwPaymentApply/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},
	$scope.listenGrid43= function(event) {//财务交易类型子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
            	var listUkey = [];
                $scope.showModalCheckBox('TB_BaseInfo_ByJylx', 'id', listUkey);
				break;
			}
			case 'event-to-delete': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwFinancialTransactionType/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	},

	$scope.listenGrid44= function(event) {//费用结算返还单子表
		var t = this;
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: null,
					accountDetailedForCompanyId:null
				});
				break;
			}
			case 'event-to-del': // 删除
			{
				var t1 = t.c.subGridObj;
				var checkStatus = layui.table.checkStatus(t1.c.id_table_sub);
				var datas = checkStatus.data;
				if (datas.length == 0) {
					layer.alert('尚未选中数据');
				} else {
					var _list = [];
					//console.log('datas',datas);
					for (var i = 0; i < datas.length; i++) {
						if(datas[i].id!=undefined && datas[i].id!=null && datas[i].id!=''){
							_list.push(datas[i].id);
						}
					}
					layer.confirm('确定要删除吗？', { icon: 3 }, function() {
						//console.log('_list',_list);
						if(_list!=null && _list.length>0){
							layer.msg('处理中', { icon: 16, shade: 0.01 });
							$.ajax({
								url: '/api/inter/tcwExpenseSettleReturn/toDelByItem',
								data: "list=" + _list,
								type: 'POST',
								async: true,
								success: function(res) {
									layer.close();
									layer.msg(res.msg);
									for (var i = datas.length - 1; i >= 0; i--) {
										var indexNum = datas[i]['_ys_sub_grid_index'];
										t1.c.sonlist.splice(indexNum, 1);
									}
									t1.reloadGrid();
								}, error: function() {
									layer.close();
									layer.msg("删除失败，请稍后再试！", { icon: 2 });
								}
							});
						}else {
							for (var i = datas.length - 1; i >= 0; i--) {
								var index = datas[i]['_ys_sub_grid_index'];
								t1.c.sonlist.splice(index, 1);
							}
							layer.closeAll();
							layer.msg("删除成功！");
							t1.reloadGrid();
						}

					}, function() {
					});
				}
				break;
			}
		};
	}
}